(ns acst.utils.escape
  (:import [org.owasp.html AttributePolicy
                           ElementPolicy
                           HtmlPolicyBuilder
                           HtmlSanitizer
                           HtmlSanitizer$Policy
                           PolicyFactory
                           Sanitizers]))

(def policies
  [Sanitizers/IMAGES
   Sanitizers/FORMATTING
   Sanitizers/BLOCKS
   Sanitizers/LINKS])

(def policy-factory
  (->>
    policies
    (reduce #(.and %1 %2))))

(defn html-sanitizer [unsafe-html]
  (.sanitize policy-factory unsafe-html))

(defn test-sanitizer []
  (html-sanitizer "
  <ul>
  <li><p><strong>URI</strong></p>
  <p><strong>/csrf-token</strong></p>
  </li>
  <li>
  <p><strong>Method</strong></p>
  <p><code>GET</code></p></li><li>
  <p><strong>Query Parma</strong></p>
  <p>无</p>
  </li>
  <li>
  <script>哈哈哈哈哈</script>
  <p><strong>Body Parma</strong></p>
  <p>无</p>
  </li>
  <li>
  <p><strong>Success Response</strong></p>
  </li>
  </ul>"))